/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uva12457;

import java.io.*;

import java.awt.geom.Point2D;
import java.text.*;
import java.math.*;
import java.util.*;

public class Main implements Runnable {

    final String filename = "in";
    double p;
    public static void main(String[] args) {
        // new Thread(new Main()).start();
        new Thread(null, new Main(), "1", 1 << 25).start();
    }

    public void run() {
        try {
            //in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
            in = new BufferedReader(new FileReader(filename + ".in"));
            // out = new BufferedWriter(new FileWriter(filename+".out"));
            int kase = iread();
            for (int i = 1; i <= kase; ++i) {
                solveD(i);
            }
            out.flush();
        } catch (Exception e) {
            System.exit(1);
        }
    }
    boolean[][] seen;
    double[][] prob;
    public void solveD(int kaseno) throws Exception {
        int n = iread();
        p = dread();
        seen = new boolean[ (n*2) +1 ][n+1];
        prob = new double[ (n*2) +1 ][n+1];
        Format db = new DecimalFormat("0.00");
        double ret = f( (n*2 ) -1, n );
        String res = db.format(ret).toString();

        out.write(res+"\n");
    }

    public double f(int left, int win){
        if(seen[left][win]==true){
            return prob[left][win];
        }
        seen[left][win]=true;
        if(win==0){
            prob[left][win]=1;
            return 1.;
        }
        if(left<=0){
            prob[left][win]=0;
            return 0.;
        }

        double ret=0;
        ret+=f( left-1, win-1)*p;
        ret+=f( left-1, win )*( ((double)1.)-p);
        prob[left][win]=ret;
        return ret;
    }

    public void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }

    public int iread() throws Exception {
        return Integer.parseInt(readword());
    }

    public double dread() throws Exception {
        return Double.parseDouble(readword());
    }

    public long lread() throws Exception {
        return Long.parseLong(readword());
    }
    BufferedReader in;
    BufferedWriter out;

    public String readword() throws IOException {
        StringBuilder b = new StringBuilder();
        int c;
        c = in.read();
        while (c >= 0 && c <= ' ') {
            c = in.read();
        }
        if (c < 0) {
            return "";
        }
        while (c > ' ') {
            b.append((char) c);
            c = in.read();
        }
        return b.toString();
    }
}